﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Model;
using DotNet.Common;

public partial class Admin_adminTemp : basePage
{
    int pagesize = 5;
    public int num = 0;
    productBll pBll = new productBll();
    productClassBll pcBll = new productClassBll();
    public string input = "<input id='HiddenUrl' type='hidden' value='&CurrentIndex=1' />";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["action"]!=null)
            {
                string action = Request.QueryString["action"].ToString();
                string id = Request.QueryString["id"].ToString();
                switch (action.Trim())
                {
                    case "delAll":
                        dellAll(id);
                        break;
                    case "can":
                        isCan(id);
                        break;
                    default:
                        break;
                }
            }
            DataTable dt = pcBll.GetDataTable();
            bindProduct();
        }
    }

    #region 根据ID号选择产品
    public string chooseProductByClassId(int cid)
    {
        string str = null;
        if (cid == 0)
        {
            str = "<font color='red'>类别未绑定</red>";
        }
        else
        {
            DataView dv = pcBll.GetModel(ViewState["dt"] as DataTable, cid);

            foreach (DataRowView row in dv)
            {
                if (row != null)
                    str = row["pClassName"].ToString();
                else
                    str = "<font color='red'>所属类别丢失</red>";
            }

        }
        return str;

    }
    #endregion

    #region 显示被屏蔽的产品---郑同飞
    public void bindProduct() 
    {
        if (Request.QueryString["CurrentIndex"] != null)
        {
            _currentIndex = Convert.ToInt32(Request.QueryString["CurrentIndex"]);
        }      
        DataTable dt = pBll.pagingForProduct(_currentIndex, pagesize,true);
        if (dt.Rows.Count == 0 && _currentIndex > 1)
        {
            _currentIndex = _currentIndex - 1;
            dt = pBll.pagingForProduct(_currentIndex, pagesize, true);
        }
        input = "<input id='HiddenUrl' type='hidden' value='&CurrentIndex=" + _currentIndex + "'/>";
        this.Repeater1.DataSource = dt;
        this.Repeater1.DataBind();
    }
    #endregion

    #region 状态维护属性---郑同飞
    private int _currentIndex = 1;
    #endregion

    #region 分页
    /// <summary>
    /// 分页
    /// </summary>
    public void htmlPaging()
    {
        string str = null;
        int count = 0;
        count = pBll.getRecordCount(true);
        int pcount = count % pagesize == 0 ? count / pagesize : count / pagesize + 1;
        str = "页次：" + _currentIndex + "/" + pcount + "  每页" + pagesize + " 总收录数据" + count + "条";
        str += HtmlControls.pagIng(_currentIndex, pcount, "adminTemp.aspx?CurrentIndex", "pageaa", "pagecurrent");

        Response.Write(str);
    }
    #endregion

    #region ajax批量删除
    public void dellAll(string id)
    {
        if (id.Contains(","))
        {
            string[] idParam = id.Split(',');
            string[] pid = new string[idParam.Length];
            for (int i = 0; i < idParam.Length; i++)
            {
                pid[i] = idParam[i];
            }
            if (pBll.Delete(pid))
            {
               
            }
        }
        else
        {

            if (pBll.Delete(Convert.ToInt32(id)))
            {

            }
        }        
    }
    #endregion

    #region 快速屏蔽
    public void isCan(string id)
    {

        bool bo = Convert.ToBoolean(Request.QueryString["bo"]);
        int isid = Convert.ToInt32(Request.QueryString["id"]);
        bool boRealut = pBll.isCan(bo, isid);
        if (boRealut != bo)
        {
            if (boRealut == true)
            {
                Response.Write("已屏蔽");
            }
            else
            {
                Response.Write("屏蔽");
            }
        }
        Response.End();

    }
    #endregion





}
